package com.example.socket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author hej
 * @date 2024/9/11 13:21
 */
public class SimpleServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket clientSocket = serverSocket.accept();

        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);

        String str = in.readLine();
        System.out.println("Client said: " + str);
        out.println("Hello, Client!");

        //回复消息
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
        bw.write("服务端返回的信息: "+str+"1"+"\n");
        bw.flush();


        in.close();
        out.close();
        clientSocket.close();
        serverSocket.close();
    }
}
